package br.com.news.business;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.business.utils.GenericBusiness;
import br.com.news.utils.business.exception.BusinessException;
import br.com.news.utils.business.interfaces.IEnqueteBusiness;
import br.com.news.utils.database.beans.EnqueteBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.IEnqueteServiceDb;

@Named
public class EnqueteBusiness extends GenericBusiness implements IEnqueteBusiness{
	
	@Inject
	private IEnqueteServiceDb enqueteServiceDb;

	@Override
	public Long save(EnqueteBean enquete) throws BusinessException {
		try {
			return enqueteServiceDb.save(enquete);
		} catch (DataBaseServiceException e) {
			throw new BusinessException("Erro ao tentar salvar a noticia", e);
		}
	}
	
	@Override
	public void update(EnqueteBean enquete) throws BusinessException {
		try {
			enqueteServiceDb.update(enquete);
		} catch (DataBaseServiceException e) {
			throw new BusinessException("Erro ao tentar dar update na enquete, camada business.",e);
		}		
	}
	
	@Override
	public List<EnqueteBean> findByQuestion(EnqueteBean questao) {
		return enqueteServiceDb.findByQuestion(questao);
	}

	@Override
	public List<EnqueteBean> findPollByStatus(boolean status) throws BusinessException {
		try {
			return enqueteServiceDb.findPollByStatus(status);
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
	}
	
	@Override
	public List<EnqueteBean> findPollActive() throws BusinessException {
		try {
			return enqueteServiceDb.findPollByStatus(true);
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
	}
	
	@Override
	public List<EnqueteBean> findAll() throws BusinessException {
		try {
			return enqueteServiceDb.findAll();
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
	}

	@Override
	public List<EnqueteBean> lastPoll() throws BusinessException {
		try {
			return enqueteServiceDb.getLastPool();
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
	}

}
